package com.springmvc.service;

import com.springmvc.dao.UserDao;
import com.springmvc.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 没有实现接口的:cglib动态代理
 */
@Service
public class UserService {

    @Autowired
    UserDao userDao;

    public User login(User user){
        return userDao.getUser(user);
    }

    public Boolean save(User user) {
        return userDao.save(user);
    }

    public Boolean saveOrUpdate(User user) {
        if(user.getId()!=null){ //有id的情况下属于编辑
            return userDao.update(user);
        }
        return userDao.save(user);
    }

    public List<User> page(Integer current,Integer pageSize,String userName){


        return userDao.page(current,pageSize,userName);

    }

    public Integer count(){
        return userDao.count();
    }

    public User getById(Long id) {
        return userDao.getById(id);
    }

    public void delById(Long id) {
        userDao.delById(id);
    }
}
